/**
 * Copyright (c) 2014 http://www.jieqianhua.com
 */
package com.hllxd.hism.star.basic.service.config.mysql;


import com.hllxd.hism.star.basic.service.config.mysql.datasource.DruidDataSourceConfiguration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.Resource;
import javax.sql.DataSource;

@Configuration
@EnableConfigurationProperties(MybatisProperties.class)
@EnableTransactionManagement
@AutoConfigureAfter({DruidDataSourceConfiguration.class, MybatisAutoConfiguration.class})
@MapperScan(
    basePackages = "com.bj58.zp.cdata.star.basic.service.dao.mapper.doris3",
//    sqlSessionFactoryRef = "dbAuthSqlSessionFactoryBean",
    sqlSessionTemplateRef = "doris3SqlSessionTemplate"
)
public class MybatisConfigurationDbDoris3 {

    private static final Logger LOGGER = LoggerFactory.getLogger(MybatisConfigurationDbDoris3.class);

    @Autowired
    private MybatisProperties properties;

    @Autowired
    private ResourceLoader resourceLoader = new DefaultResourceLoader();

    @Resource(name = "dorisDataSource3")
    private DataSource dorisDataSource3;

    @Bean(name = "doris3SqlSessionFactoryBean")
    public SqlSessionFactory dorisSqlSessionFactoryBean() throws Exception {
        return MybatisConfiguration.getSqlSessionFactory(resourceLoader, properties, dorisDataSource3);
    }


    @Bean(name = "doris3SqlSessionTemplate")
    public SqlSessionTemplate dorisSqlSessionTemplate(
        @Qualifier(value = "doris3SqlSessionFactoryBean") SqlSessionFactory dorisSqlSessionFactoryBean) {
        return new SqlSessionTemplate(dorisSqlSessionFactoryBean);
    }
}

